<template>
<<<<<<< HEAD
    <h1>布置作业</h1>
  
</template>

<script setup>
</script >
<style lang="less" scoped>
</style>
=======
    <div>
        <div class="container">
            <div class="handle-box">
                <label class="label" >所属课程：</label>
                <el-input class="handle-input" v-model="form.clazz" >   
                    <template #append>          
                        <el-select  v-model="form.clazz" style="width: 44px;" :suffix-icon="CaretBottom">
                            <el-option
                            v-for="item in options.organizations"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            />
                        </el-select>
                </template>   
                </el-input>
                    <el-button color="#0ab394" class="handle-btn"  @click="handleSearch">查询</el-button>
                    <el-row class="top-btn">
                     <!-- <el-button-group class="ml-4"> -->
                        <el-button color="#0ab394"  @click="open">添加</el-button> 
                        <el-button color="#e35148" @click="handleAllDelete">删除</el-button>                         
                    <!-- </el-button-group> -->
                </el-row>
                </div>
                <el-table ref="multipleTableRef" 
                    :header-cell-style="{color:'#2A62BC'}"
                     :data="tableData"   
                     style="width: 100%;" 
                     height="380"
                    size="small"
                    border
                    @selection-change="handleSelectionChange">
                    <el-table-column   type="selection" width="35" />
                    <el-table-column  prop="title" label="标题"  ></el-table-column>
                    <el-table-column prop="context" label="内容"></el-table-column>
                    <el-table-column prop="file" label="文件"></el-table-column>
                    <el-table-column prop="course" label="所属课程"></el-table-column>
                    <el-table-column prop="clazz" label="所属班级"></el-table-column>
                    <el-table-column prop="create_time" label="创建时间"></el-table-column>
                    <el-table-column label="操作" width="260" align="center" >
                        <template #default="scope">
                            <el-row class="right-btn">
                                <el-button color="#0ab394" :icon="Edit" @click="open(scope.$index,scope.row)" >修改</el-button>
                                <el-button color="#e35148" :icon="Delete"  @click="handleDelete(scope.$index)">删除</el-button>
                                <el-button color="#23c6c8" style="color: #fff;"   @click="downloadFile(scope.$index,scope.row)">
                                    <i class="iconfont icon-download2 white"></i>
                                    下载</el-button>
                            </el-row>
                            <!-- </el-button-group> -->
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <div class="pagination">
                    <el-pagination
                    :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :page-sizes="[5, 10, 15, 20]"
                        size="small"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageTotal"
                        @size-change="handleSizeChange"
                        @current-change="handlePageChange"/>
                </div>
        </div>
    
            <!-- 修改/添加弹出框 -->
            <el-dialog :title="titleEdit" v-model="editVisible" width="675" >
                <el-form label-width="75px">
                    <el-form-item label="所属班级:">
                        <el-input class="dialog-input" v-model="form.clazz" >   
                            <template #append>          
                                <el-select  v-model="form.clazz" style="width: 44px;" :suffix-icon="CaretBottom">
                                    <el-option
                                    v-for="item in options.organizations"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    />
                                </el-select>
                            </template>   
                        </el-input>
                    </el-form-item>
                    <el-form-item label="课程:">
                        <el-input class="dialog-input" v-model="form.course"   >
                            <template #append>          
                                <el-select  v-model="form.course" style="width: 44px;" :suffix-icon="CaretBottom">
                                    <el-option
                                    v-for="item in options.organizations"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    />
                                </el-select>
                            </template>   
                        </el-input>
                    </el-form-item>
                    <el-form-item label="所属章:">
                        <el-input class="dialog-input" v-model="form.chapter" >
                            <template #append>
                                <el-select v-model="form.chapter" style="width: 44px;" :suffix-icon="CaretBottom">
                                    <el-option
                                        v-for="item in options.organizations"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                        />
                                 </el-select>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="所属节:">
                        <el-input class="dialog-input" v-model="form.subsection">
                            <template #append>
                                <el-select v-model="form.subsection" style="width: 44px;" :suffix-icon="CaretBottom">
                                    <el-option
                                    v-for="item in options.organizations"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    />
                                </el-select>
                            </template>
                    </el-input>
                    </el-form-item>
                    <el-form-item label="作业标题:">
                        <el-input v-model="form.title" placeholder="请输入标题"></el-input>
                    </el-form-item>
                    <el-form-item  label="附件上传:">
                        <el-input type="file"></el-input>
                    </el-form-item>
                    <el-form-item label="作业内容:">
                        <el-input v-model="form.context" type="textarea"
                        placeholder="">
                        </el-input>
                    </el-form-item>
                </el-form> 
                <template #footer>
                    <span class="dialog-footer">
                        <el-button color="#0ab394" @click="editVisible = false">关闭</el-button>
                        <el-button color="#0ab394" @click="saveEdit">确 定</el-button>
                    </span>
                </template>
            </el-dialog>
           
    
            <!-- </div> -->
        </div>
    </template>
    
    <script setup >
    import { ref, reactive } from 'vue';
    import { ElMessage, ElMessageBox } from 'element-plus';
    import { Delete, Edit, Search, CaretBottom } from '@element-plus/icons-vue';
    import { getHomeWorks} from '../../api/clazz' ;
    let form = reactive({
        id:'',
        title:'', 
        context:'' ,
        file:'' ,
        course:'',
        clazz:'' ,
        create_time: '',
        subsection:'',
        chapter:'',
    });
    

    const options = reactive({
    organizations:[
        {  
            id:'1',
            value: '天龙八部',
            label: '天龙八部',
          },
      {
        value: '神雕侠侣',
        label: '神雕侠侣',
      },
      {
        value: '仙剑奇侠传',
        label: '仙剑奇侠传',
      },
      {
        value: 'flyme',
        label: 'flyme',
      },],
      
    }
    )
        
    //分页字体
    const small = ref(true)
    // const size = ref<'default' | 'large' | 'small'>('default')
    
    //分页数据
    const query = reactive({
        pageIndex: 1,
        pageSize: 5,
    });
    //
    
    //表格数据
    const tableData = ref();
    //总页数
    const pageTotal = ref(0);
    const multipleTableRef = ref()
    const state = reactive({
        multipleSelection:[]
    })
    
    // 获取表格数据  分页是数据截取  后台结合一起后  直接返回分页的后的数据
    const getData = () => {
        getHomeWorks({pageCurrent:query.pageIndex,pageSize:query.pageSize}).then(res=>{
            console.log(res,"---res---")
            // tableData.value = res.data.
            let start  = (query.pageIndex-1)*query.pageSize;//开始位置
            let end =query.pageIndex*query.pageSize  ;//结束位置 数组的截取的时候 [start,end) suo所以不用-1
            tableData.value = res.data.slice(start,end);
            // tableData.value = res.data;
            pageTotal.value = res.data.length
        })
       
        
    };
    getData();
    //多选框权限
    const handleSelectionChange = (val) => {
      state.multipleSelection = val
    }
    // 分页导航
    const handleSizeChange = (val) => {
      // console.log(`${val} items per page`)
      query.pageSize = val;
      getData()
    }
    const handlePageChange = (val) => {
        query.pageIndex = val;
        console.log(val,"==")
        console.log(query.pageSize)
        getData()
    };
    
    
    //是够启用调用后台接口
    const  changeSwitch=(status)=>{
        //调用后台修改接口
        console.log(status,'>>>status');
    }
    
    // 删除单个操作
    const handleDelete = (index) => {
        // 二次确认删除
        ElMessageBox.confirm('确定要删除吗？', '提示', {
            type: 'warning'
        })
        .then(() => {
            ElMessage.success('删除成功');
            //to 传递id 到后台 
            tableData.value.splice(index, 1);
            // 删除成功后
            // getData()
        })
        .catch(() => {});
    };
    //删除多个数据  to......
    const handleAllDelete =()=>{
        // console.log('删除多个')
        console.log(state.multipleSelection,'===拿到所有选择的数据====')
        if (state.multipleSelection.length==0) {
            ElMessage.error('请选择项')
            return
          }
        // console.log(state.multipleSelection.map(item=>item.id))
        //axios删除的操作
        // deleteAllAdmin({ids:state.multipleSelection.map(item=>item.id)})
    
        
    }
    
    
    // 查询操作  to... 需要自己实现与后台交互
    const handleSearch = () => {
        query.pageIndex = 1;
        getData();
    };
    
    // 表格编辑时弹窗和保存
    const editVisible = ref(false);
    let titleEdit = ref('修改')
    const open  = (index,row)=>{//index是时间源对象
        if(row){
            titleEdit.value = "修改"
            console.log(editVisible.value,'<<<xiuga')
            handleEdit(index,row)
        }else{
            console.log(editVisible.value,'1<<<xiuga')
            //清空表单中的数据form.
            titleEdit.value = "添加";
            form.title=''
            form.context='' 
            form.file='' 
            form.course=''
            form.clazz='' 
            form.create_time= ''
            editVisible.value = true	
        }
        console.log('-------修改/添加弹窗-------')
       
    
    }
    let idx = -1;
    const handleEdit = (index,row) => {
        idx = index;
        form.id = row.id;
        form.title=row.title
        form.file=row.file
        form.context=row.context
        form.course=row.course
        form.clazz=row.clazz
        form.create_time=row.create_time
        editVisible.value = true;
    };
    //保存添加或者修改的数据 ---需要重新实现
    const saveEdit = () => {
        editVisible.value = false;
        ElMessage.success(`修改第 ${idx + 1} 行成功`);
        tableData.value[idx].title = form.title;
        tableData.value[idx].context= form.context;
        tableData.value[idx].course = form.course;
        tableData.value[idx].clazz = form.clazz;
        tableData.value[idx].file = form.file;
        tableData.value[idx].create_time = form.create_time;
    };
    
    //下载
    const  downloadFile=(index,row)=>{
        ElMessageBox.alert('下载成功', '127.0.0.1:5500显示', {
    // if you want to disable its autofocus
    // autofocus: false,
    confirmButtonText: '确定',
    
  })
    }
    
    
    </script >
    <style lang="less" scoped>
    .handle-box {
        margin-bottom: 20px;   
        .handle-btn{
            margin-left: 8px;
        }    
    }
  
    .handle-input {
        width:200px;
        margin-right: 8px;
    }
    .label{
       display: inline-block;
       max-width:100%;
       margin: 5px;
       font-weight: 700; 
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #F56C6C;
    }
    .blue {
        color: #1296e2;
        font-weight: bold;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
    .cell{
        display: inline-block;
        .el-button{
            margin-left: 0px;
        }
    }
    .el-col {
      border-radius: 4px;
      margin-left: 10px;
    }
    .el-button-group{
        float: right;
    }
    .top-btn{
        float: right;
        .el-button{
            margin-left: 5px;
        }
    }
    .right-btn{
         justify-content:center;
        .el-button{
            height: 22px;
            // width: 60px;
            margin-right: 10px;
            padding: 1px 5px;
        }
    }
    
    
    </style>
>>>>>>> c088509ecc2282a34d0b932f6925d649261c336d
